import { createRouter, createWebHistory } from 'vue-router'
import config from '../config'
import systemRoutes from './modules/system'
// import logo from '@/assets/login/logo.png'
import autoRoute from '@/utils/auto-route'
const BASE = config.base

// 项目路由
const projectRoutes = [
  {
    path: `${BASE}/board`,
    component: () => import('@/views/board/index.vue'),
    meta: {
      appAlone: true,
    },
  },
]

/**
 * 自动导入modules文件夹下的路由
 */
// const modules = import.meta.globEager('./modules/*.js')
const modules = import.meta.glob('./modules/*.js', {
  eager: true, // 非懒加载
  import: 'default', // 直接拿到default中的数据
})

const filter = ['./modules/system.js']
for (const key in modules) {
  if (Object.hasOwnProperty.call(modules, key) && !filter.includes(key)) {
    const element = modules[key]
    projectRoutes.push(...element)
  }
}
// 路由信息
const routes = [
  { path: ``, redirect: `${BASE}` },
  {
    path: `${BASE}/login`,
    // component: () => import('jax-node/views/login/login.vue'),
    component: () => import('jax-node/views/login/login-2023.vue'),
    meta: {
      sloganTop: '欢迎来到',
      sloganBottom: '五粮液鉴定服务站',
      // logo,
    },
  },
  {
    path: `${BASE}`,
    component: () => import('jax-admin/layout/Layout.vue'),
    // component: () => import('../views/admin/Layout.vue'),
    children: [
      ...systemRoutes,
      ...projectRoutes,
      ...autoRoute(),
      // {
      //   path: `/:catchAll(.*)*`,
      //   alias: '/404',
      //   component: () => import('@/views/404.vue'),
      // },
    ],
  },
  {
    path: `/:catchAll(.*)*`,
    name: 'NotFound',
    alias: '/404',
    component: () => import('@/views/404/index.vue'),
    meta: {
      title: '404',
    },
  },
  // {
  //   path: `${BASE}/demo`,
  //   component: () => import('jax-node/views/demo/index.vue'),
  // }
]

// 导出路由
const router = createRouter({
  history: createWebHistory(),
  routes,
})

export default router
